import pandas as pd
import pymysql

def out(name,count,count_type):
    data=pd.read_csv("E:\\djangoProject\\Try\\"+name+".csv",encoding='GBK',sep=',',error_bad_lines=False)
    title=list(data.get("title"))
    author=list(data.get("author"))
    source=list(data.get("resource"))
    time=list(data.get("time"))
    download=list(data.get("download"))
    link=list(data.get("link"))
    conn=pymysql.connect(
        host='127.0.0.1',
        user='root',
        passwd='111111',
        port=3306,
        db='dj04'
    )
    cur=conn.cursor()#生成游标对象
    x=len(time)
    for i in range(0,x):
        #插入语句
        sql = "INSERT INTO article VALUES(%s,'%s','%s','%s','%s','%s',%s,'内容空','%s')" % (count,title[i],author[i],source[i],time[i],download[i],count_type,link[i])
        count+=1
        try:
            cur.execute(sql)#执行插入的语句
            conn.commit()#提交到数据库执行
        except:
            conn.rollback()#如果发生错误则回滚
    cur.close()
    conn.close()